package com.zly.mybatisdemo.controller;

import com.mysql.cj.util.StringUtils;
import com.zly.mybatisdemo.model.Event;
import com.zly.mybatisdemo.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("Event")
public class EventController {
    @Autowired
    private EventService eventService;

    @PostMapping("/AllEvent")
    public List<Event> findAllEvent() {
        return eventService.findAllEvent();
    }

    @GetMapping("/AddEvent")
    public boolean addEvent(String name, String startTime,String comments) {
        if (StringUtils.isNullOrEmpty(name)||StringUtils.isNullOrEmpty(startTime)||StringUtils.isNullOrEmpty(comments))
        {
            return false;
        }
        Event event = new Event();
        event.setName(name);
        event.setStartTime(startTime);
        event.setComments(comments);
        return eventService.addEvent(event)>0;
    }

}
